<template>
  <!-- 交易查询明细 -->
  <el-drawer
    :title="title"
    :visible.sync="drawerDetail"
    :direction="direction"
    :before-close="handleClose"
    destroy-on-close
    :append-to-body="true"
    :modal-append-to-body="false"
    custom-class="drawerClass"
    size="50%"
  >
    <!-- <div class="searchNav" style="padding: 0 20px">
      <div class="block" v-if="titleType=== '添加'">
        <el-date-picker v-model="range" type="daterange" style="width: 250px; margin-left: 10px" start-placeholder="开始日期"
          end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="changeTime">
        </el-date-picker>
      </div>
      <div class="searchParams">


      </div>
    </div> -->
    <div>
      <div style="padding: 15px 30px 10px 30px">
        <el-descriptions title="" :column="2" size="medium" border>
          <el-descriptions-item label="赊货方">
            {{ DealDetaila.ByerRealName }}</el-descriptions-item
          >
          <el-descriptions-item label="销售方">{{
            DealDetaila.CompanyName
          }}</el-descriptions-item>
          <el-descriptions-item label="赊货发起日期">{{
            DealDetaila.CreateTime
              ? DealDetaila.CreateTime.substring(0, 10)
              : ""
          }}</el-descriptions-item>
          <el-descriptions-item label="货品交付日期">{{
            DealDetaila.SignTime ? DealDetaila.SignTime.substring(0, 10) : ""
          }}</el-descriptions-item>
          <el-descriptions-item label="本次总金额">
            {{ toThousands(DealDetaila.PendingSum) }}
          </el-descriptions-item>
          <el-descriptions-item label="联系电话">{{
            DealDetaila.ByerPhone
          }}</el-descriptions-item>
          <el-descriptions-item label="联系地址">{{
            DealDetaila.cCusAddress
          }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <div style="padding: 20px">
        <el-table
          :data="detailedListData"
          style="width: 100%"
          :max-height="height"
          v-loading="loading"
        >
          <el-table-column prop="InventName" label="品名/编码">
            <template slot-scope="scope">
              {{ scope.row.InventName + "/" + scope.row.cInvCode }}
            </template>
          </el-table-column>
          <el-table-column prop="Quantity" label="数量" width="200">
          </el-table-column>
          <el-table-column prop="Price" label="单价">
            <template slot-scope="scope">
              {{ toThousands(scope.row.Price) }}
            </template>
          </el-table-column>
          <el-table-column prop="Money" label="金额">
            <template slot-scope="scope">
              {{ toThousands(scope.row.Money) }}
            </template>
          </el-table-column>
          <!-- <el-table-column label="操作" width="70" align="center">
          <template slot-scope="scope">
            <el-button v-if="scope.row.Type!=0" type="text" @click="handleView(scope.row)">详情</el-button>
          </template>
        </el-table-column> -->
        </el-table>
        <!-- <el-pagination layout="total,prev, pager, next,sizes" :total="pagination.total" :current-page="pagination.current"
        :page-size="pagination.pageSize" :page-sizes="pagination.pageSizeOptions"
        style="text-align: right; margin-top: 8px; padding: 0" @current-change="currentChange"
        @size-change="handleSizeChange">
      </el-pagination> -->
      </div>
    </div>

    <div style="height: 50px"></div>
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '5px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 99999,
      }"
    >
      <el-button @click="drawerDetail = false">取消</el-button>
    </div>
    <!-- <el-dialog title="编辑商品分类" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" append-to-body>
      <el-input v-model="typeObj.Name" placeholder="请输入商品分类名称"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button :loading="dialogLoading" type="primary" @click="dialogConfirm">确 定</el-button>
      </span>
    </el-dialog> -->
  </el-drawer>
</template>

<script>
import { getMonthRange, toThousands } from "../../utils/Tools";

export default {
  components: {},
  props: {
    parentObj: { type: Object },
  },
  data() {
    return {
      getMonthRange,
      toThousands,
      // 日期
      range: [],
      drawerDetail: false,
      direction: "rtl",
      btnLoading: false,
      title: "",
      loading: false,
      timeout: null,
      entity: {},
      tableData: [],
      pagination: {
        current: 1,
        pageSize: 25,
        total: 0,
        pageSizeOptions: [25, 50, 100],
      },
      sorter: {
        field: "CreateTime",
        order: "desc",
      },
      queryParam: {
        // 客户id
        CustomerId: "",
        // 开始时间
        StartTime: "",
        // 结束时间
        EndTime: "",
      },
      sortList: [1, 2, 3, 4, 5, 6],
      selectRows: [],
      activeName: "2",
      tagList: [],
      dialogVisible: false,
      typeObj: {},
      dialogLoading: false,
      // 传递过来的对账单列表id
      BillConfirmId: "",
      // 客户id
      CustomerId: "",
      CompanyId: "",
      // 时间范围
      range: [],
      // 点击的是添加还是查看
      titleType: "",
      // 明细当前数据
      DealDetaila: {},
      detailedListData: [],
    };
  },
  computed: {
    height() {
      return document.documentElement.clientHeight * 0.75;
    },
  },
  methods: {
    // 对账单添加
    arrearListAdd() {},
    // 开始日期结束日期选择事件
    changeTime(e) {
      console.log("时间选择", e);
    },
    dialogConfirm() {
      if (!this.typeObj.Name) return this.$message.error("请输入商品分类名称");
      if (!this.typeObj.CompanyId)
        this.typeObj.CompanyId = this.queryParam.CommpayId;
      this.dialogLoading = true;
      this.$http.post("/BO/InventType/SaveData", this.typeObj).then((res) => {
        this.dialogLoading = false;
        if (res.Success) {
          this.dialogVisible = false;
          this.$message.success("操作成功");
          this.getDataList();
        } else {
          this.$message.error(res.Msg);
        }
      });
    },
    // 列表项编辑
    handleView(row) {
      console.log("row", row);
      this.typeObj = row;
      // this.dialogVisible = true;
      // 打开明细弹窗
      this.$refs.ProductDetail.openForm(row.BillId);
    },
    // 分类新增
    handleAdd() {},
    currentChange(page) {
      this.pagination.current = page;
      this.getDataList();
    },
    handleSizeChange(lint) {
      this.pagination.pageSize = lint;
      this.getDataList();
    },
    saveCustomerGoods() {
      this.$http
        .post("/BO/InventCustomers/AddDataList?Code=" + this.entity.cInvCode, {
          Data: this.tableData,
        })
        .then((res) => {
          if (res.Success) {
            this.$message.success("操作成功");
            this.parentObj.getDataList();
            this.drawerDetail = false;
            // 显示删除按钮
            this.titleType = "";
          } else {
            this.$message.error(res.Msg);
          }
        });
    },
    handleSelectionChange(val) {
      this.selectRows = val;
    },

    handleDelete(scope) {
      this.tableData.splice(scope.$index, 1);
    },
    init() {
      this.drawerDetail = true;
    },

    // 删除
    arrearDetailDelete() {
      this.$http
        .post("/BO/BIllcollection/DeleteConfirmData", [this.BillConfirmId])
        .then((resJson) => {
          if (resJson.Success) {
            this.loading = false;
            // 刷新父组件的列表方法
            this.parentObj.tableData = [];
            this.parentObj.getBillConfirmList();
            this.$message.success("已删除");
            // 关闭当前弹窗
            this.drawerDetail = false;
          } else {
            this.$message.error(resJson.Msg);
            this.loading = false;
          }
        });
    },

    // 保存
    arrearDetailSave() {
      this.loading = true;
      console.log("打印父组件", this.parentObj);
      this.$http
        .post("/BO/BIllcollection/SaveBillConfirmData", this.entity)
        .then((resJson) => {
          if (resJson.Success) {
            this.loading = false;
            // 刷新父组件的列表方法
            this.parentObj.tableData = [];
            this.parentObj.getBillConfirmList();
            this.$message.success("已保存");
            // 关闭当前弹窗
            this.drawerDetail = false;
          } else {
            this.$message.error(resJson.Msg);
            this.loading = false;
          }
        });
    },
    // 获取欠款对账单
    getBillConfirmList() {
      this.loading = true;
      this.$http
        .post("/BO/BIllcollection/GetReconciliationData", {
          BillConfirmId: this.BillConfirmId,
          CompanyId: this.CompanyId,
          CustomerId: this.CustomerId,
          EndTime: this.range[1],
          StartTime: this.range[0],
        })
        .then((resJson) => {
          if (resJson.Success) {
            this.loading = false;
            console.log(
              "获取欠款对账单详情详情详情详情详情详情详情详情详情详情详情详情详情",
              resJson.Data
            );
            this.entity = resJson.Data;
            this.tableData = resJson.Data.BIllcollectionList;
            if (this.tableData) {
              const pagination = { ...this.pagination };
              pagination.total = resJson.Total;
              this.pagination = pagination;
            }
          } else {
            this.loading = false;
          }
        });
    },
    openForm(row) {
      console.log("传递过来的交易查询行数据", row);
      this.init();
      this.title = "交易明细";
      this.getDataInfo(row);
    },
    //获取当前商品的基本信息
    getDataInfo(row) {
      var that = this;
      // 显示加载状态
      this.loading = true;
      this.$http
        .post("/Base/Bank_Info/TransactionDtails", {
          id: row,
        })
        .then((res) => {
          console.log(res);
          if (res.Success) {
            // 获取对应的参数
            this.DealDetaila = res.Data.maindata;
            this.detailedListData = res.Data.detalist;
            setTimeout(function () {
              that.loading = false;
            }, 600);
          }
        });
    },
    // 获取商品分类列表数据
    getDataList() {
      this.loading = true;
      this.$http
        .post("/Base/Bank_Info/TransactionDtails", {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || "Id",
          SortType: this.sorter.order,
          Search: this.queryParam,
          id: this.BillConfirmId,
        })
        .then((resJson) => {
          console.log(resJson);
          this.loading = false;
          if (resJson.Success) {
            this.tableData = resJson.Data;
            if (this.tableData) {
              const pagination = { ...this.pagination };
              pagination.total = resJson.Total;
              this.pagination = pagination;
            }
          }
        });
    },

    handleClose(done) {
      done();
    },
    handleSelect(item) {
      console.log(item);
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-drawer__header {
  margin-bottom: 10px;
}
.qianImg {
  width: 70px;
  height: 160px;
  transform: rotate(-90deg);
}

.drawerClass {
  padding: 10px;

  .posBox {
    font-weight: 600;
    width: calc(100% - 42px);
    margin-left: 42px;
    line-height: 2;
    color: #333;
    border-bottom: 1px solid #ccc;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
  }
}
</style>
